/**
 * 
 */
package com.admin.his.config.interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.admin.his.common.dto.UserContext;
import com.admin.his.common.dto.UserContextHolder;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

/**
 * @author 张三
 *
 */
public class UserContextInteceptor implements HandlerInterceptor{

	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
			throws Exception {
		HttpSession session = request.getSession(false);
		if(session!=null) {
			UserContext uc=(UserContext) session.getAttribute(UserContext.class.getName());
			if(uc!=null) {
				//获取当前登录ip
				String currentLoginIp = request.getRemoteHost();
				uc.setCurrentLoginIp(currentLoginIp);
				UserContextHolder.hold(uc);
			}
		}
		
		
		return true;
	}
}
